<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" >
        <el-form-item label="科室" >
        <el-select
         class="datawidth"
          v-model="queryParams.depOffId"
          placeholder="请选择科室"
          clearable
          size="small"
        >
          <el-option
            v-for="(dict,index) in keshiList"
            :key="index"
            :label="dict.depOffName"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
      <el-radio v-model="queryParams.type" label="1" class="zdfilm">最低值</el-radio>
      <el-radio v-model="queryParams.type" label="2" class="zdfilm">最大值</el-radio>
      <el-radio v-model="queryParams.type" label="3" class="zdfilm">半年未操作</el-radio>
      <el-radio v-model="queryParams.type" label="" class="zdfilm">全部</el-radio>
      </el-form-item>
      <el-form-item>
        <el-button  type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
        <el-button  type="success" icon="el-icon-plus" size="mini" @click="saveBtn">保存</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="科室"   property="depOffName" :show-overflow-tooltip="true"  ></el-table-column>

      <el-table-column align="center" label="物料编码" property="mno" :show-overflow-tooltip="true" width="150" ></el-table-column>
      <el-table-column align="center" label="物料名称"  property="mname" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="物料规格"  property="mmodel" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="分类名称"  property="typeName" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="入库时间"  property="crtTime" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="单位"  property="unit" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="计划价"  property="planPrice" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="库存"  property="inventory" ></el-table-column>
      <el-table-column align="center" label="创建日期"  property="updaTime" ></el-table-column>
      <el-table-column
        label="最低值"
        align="center"
        width="150">
        <template slot-scope="scope">
          <el-input
              type="number"
              v-model="scope.row.warningSmall"
              placeholder
              @input="zdNum(scope)"
            ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="最大值"
        align="center"
        width="150">
        <template slot-scope="scope">
          <el-input
              type="number"
              v-model="scope.row.warningBig"
              placeholder
              @input="xqNum(scope)"
            ></el-input>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="闲置值"
        align="center"
        width="150">
        <template slot-scope="scope">
          <el-input
          class="showts"
              type="number"
              v-model="scope.row.warningBig"
              placeholder
              @input="xqNum(scope)"
            ></el-input>
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="差异值"  property="warningIdle" >
      </el-table-column>
      <el-table-column
      label="提示"
      align='center'
      width="150">
          <template slot-scope="scope" style="text-align: center">
          <div style="background:red  ;color: white;width: 120px;height: 24px;display: inline-block" v-show="scope.row.pd=='1'">库存低于最低值</div>
          <div style="background:#DEA11E  ;color: white;width: 120px;height: 24px;display: inline-block" v-show="scope.row.pd=='2'">库存大于最大值</div>
          <div style="background:red  ;color: white;width: 120px;height: 24px;display: inline-block" v-show="scope.row.updaTimeC+183*24*60*60*1000<getMesc">半年未操作</div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />
    <!-- <el-dialog
      title="修改库存"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="400px">
      <el-form :model="kcNum" ref="queryForm" :inline="true" label-width="90px">
        <el-form-item label="库存数量" >
          <el-input
            v-model="kcNum.demandNum"
            placeholder="请输入库存数量"
            clearable
            size="small"
          />
        </el-form-item>

      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button  size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button  size="small" type="primary" @click="xiugaiBtn">确 定</el-button>
      </span>
    </el-dialog> -->
    <!-- <el-dialog
      title="修改"
      :visible.sync="dialogVisibleyj"

      :close-on-click-modal="false"
      width="400px">
      <el-form :model="kcParams" ref="queryForm" :inline="true" label-width="90px">
        <el-form-item label="最低值" >
          <el-input
            v-model="kcParams.zdFilm"
            placeholder="请输入最低值"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="闲置值" >
          <el-input
            v-model="kcParams.xzFilm"
            placeholder="请输入闲置值"
            clearable
            size="small"
          />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button  size="small" @click="dialogVisibleyj = false">取 消</el-button>
        <el-button  size="small" type="primary" @click="xiugaiBtnyj">确 定</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>

<script>
  import request from '@/utils/request'
//   import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
//   import kucunLog from "./kucunLog";
//   import { getToken } from "@/utils/auth";
//   import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user";

  export default {
    name: "Role",
    components:{
    //   kucunLog
    },
    data() {
      return {
        // dialogVisible:false,
        // dialogVisibleyj:false,
        // kuncunData:{},
        // kucunShow:false,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [
          { jhdh:'CGJH2020000265',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'1',spjssj:'2020-10-02'},
          { jhdh:'CGJH2020000264',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'2',spjssj:'2020-10-02'},
          { jhdh:'CGJH2020000263',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'3',spjssj:'2020-10-02'}
        ],
        fenleiList:[],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        //最低和闲置值
        //  type:'',
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          type:'',
          depOffId:''
        },
        // kcParams:{
        //   zdFilm:'',
        //   xzFilm:''
        // },
        // kcNum:{
        //     demandNum:''
        // },
        // 表单参数
        form: {},
        //科室信息
        keshiList:[],
        Mesc:null,
        //半年的毫秒数
        // bnMesc:183*24*60*60*1000
      };
    },
    created() {
      // var Mesc = new Date().getTime()
      this.getwlks()
      this.search()
    },
    computed:{
       getMesc () {
         this.Mesc = new Date().getTime()
         return this.Mesc
       }
    },
    methods: {
      //查询
      search:function(){
        this.loading = true
        console.log(this.queryParams)
        request({
          url: 'material/supplies/listByHouse',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          this.reviseDate()
          console.log(this.roleList)
          this.total = response.total

        });
      },
      //修改返回的日期
      reviseDate () {
        this.roleList.forEach(item =>{
          item.updaTime = item.updaTime.substr(0,10)
        })
      },
      zdNum (scope) {
        scope.row.warningSmall = parseInt(scope.row.warningSmall)
        if(scope.row.warningSmall<0) {
          this.$message({
            type:'warning',
            message:'最低值不能小于零'
          })
        }
      },
      xqNum (scope) {
        console.log(scope.row)
        scope.row.warningBig = parseInt(scope.row.warningBig)
        // this.shows()
        if(scope.row.warningBig<scope.row.warningSmall) {
           this.$message({
            type:'warning',
            message:'最大值不能小于最低值'
          })
        }
      },
      // shows (scope) {
      //   if(scope.row.warningBig==0||scope.row.inventory<scope.row.warningBig) {
      //     return false
      //   } else if(scope.row.inventory>scope.row.warningBig) {
      //     return true
      //   }
      // },
      //保存
      saveBtn () {
          this.$confirm('确认保存?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() =>{
            //调用接口

            this.save()
        })
      },
      //判断
      // pd () {
      //    for (let index = 0; index < this.roleList.length; index++) {
      //      if(this.roleList[index].warningBig<this.roleList[index].warningSmall)
      //      return
      //    }
      // },
      save () {
         for (let index = 0; index < this.roleList.length; index++) {
           if(this.roleList[index].warningBig) {
              if(this.roleList[index].warningBig<=this.roleList[index].warningSmall) {
             this.$message({
            type:'warning',
            message:'保存失败-最大值不能小于或等于最低值'
            })
             return
           }
          }
           
         }
        request({
            url:"system/suppliesWarehousea/updateSuppliesByYj",
            method:'put',
            data:this.roleList
          }).then(response=>{
            if(response.code==200) {
              this.search()
              this.$message({
                type:'success',
                message:"保存成功"
               })
            }
        })
      },
      //获取物料科室数据
      getwlks:function(){
        request({
          url: '/system/off/list',
          method: 'get',
          params: {
            pageNum:'1',
            pageSize:'10000',
          }
        }).then(response => {
          this.keshiList = response.rows
          this.keshiList.unshift({
            depOffName:'全部',
            id:''
          })
          console.log(this.keshiList)
        });
      },
      //库存编辑
    //   handleEdit:function (index,row) {
    //     console.log('编辑',row)
    //     this.dialogVisible = true
    //     this.kcNum.demandNum = row.demandNum
    //   },
    //   xiugaiBtn () {
    //       this.$message({
    //           type:'warning',
    //           message:'确认修改？'
    //       }).then(
    //           //调用接口

    //           this.search(),
    //       )
    //     this.dialogVisibleyj =false
    //   },
      //预警
    //   handleYJ:function (index,row) {
    //     this.dialogVisibleyj = true
    //     console.log(row)
    //     this.kcParams.zdFilm = row.demandNum
    //     this.kcParams.xzFilm = row.id
    //   },
    //   xiugaiBtnyj () {
    //       this.$message({
    //           type:'warning',
    //           message:'确认修改？'
    //       }).then(
    //           //调用接口
    //           this.search(),
    //       )
    //     this.dialogVisibleyj =false
    //   }
    }
  };
</script>

<style lang="scss">
.showts {
    border-radius: 1px;
    border: 1px solid orange;
}
.zdfilm {
  font-weight: 700;
  margin-top: 10px;
  padding-left: 10px;
  padding-right: 10px;
}
</style>
